//
//  CatUIButton.m
//  TomCat
//
//  Created by aaaaaa on 16/6/9.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CatUIButton.h"

@implementation CatUIButton

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc
{
    [_imageArray release];
    [_catImageView release];
    [super dealloc];
}


+ (instancetype)buttonWithFrame:(CGRect)frame withImageName:(NSString *)imageName withImageCount:(NSInteger)imageCount{
    
    CatUIButton * button = [CatUIButton buttonWithType:UIButtonTypeCustom];
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
    [button setImage:[UIImage imageWithContentsOfFile:imagePath] forState:UIControlStateNormal];
    
    [button setPropertyWithFrame:frame withImageName:imageName withImageCount:imageCount];
    return button;
}

+ (instancetype)buttonNoImageWithFrame:(CGRect)frame withImageName:(NSString *)imageName withImageCount:(NSInteger)imageCount{
    CatUIButton *button = [CatUIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor clearColor];
    [button setPropertyWithFrame:frame withImageName:imageName withImageCount:imageCount];
    return button;
}


- (void)setPropertyWithFrame:(CGRect)frame withImageName:(NSString *)imageName withImageCount:(NSInteger)imageCount{
    self.imageArray = [NSMutableArray arrayWithCapacity:0];
    for (int i = 0; i < imageCount; i++) {
        NSString *imageStr = [NSString stringWithFormat:@"%@_%02d", imageName, i];
        NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageStr ofType:@"jpg"];
        UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
        [self.imageArray addObject:image];
    }
    self.frame = frame;
}




















@end
